package Heap;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        Heap heap=new Heap();
        heap.initElem(new int[]{27,15,19,18,28,34,65,49,25,37});
        test1(heap);
        test2();

        //堆排序
        Heap heap1=new Heap();
        heap1.initElem(new int[]{27,15,19,18,28,34,65,49,25,37});
        test3(heap1);
    }

    public static void test1(Heap heap) {
        System.out.println("===========test1===========");
        heap.creatHeap();
        System.out.println("创建的大根堆的结果为:"+Arrays.toString(heap.elem));

        heap.offer(80);
        System.out.println("插入元素后大根堆的结果:"+Arrays.toString(heap.elem));

        heap.pop();
        System.out.println("删除元素后大根堆的结果:    "+Arrays.toString(heap.elem));
        System.out.println("===========test2============");
    }
    public static void test2() {
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>();
        //默认建造一个小根堆，插入和删除都会进行一个比较   10      2
        //                                       /   ->  /
        //                                      2      10
        Queue<Integer> priorityQueue1=new PriorityQueue<>();
        priorityQueue1.offer(10);
        priorityQueue1.offer(2);
        System.out.println(priorityQueue1.poll());

        //可以通过一个集合类来创建优先级队列
        List<Integer> list=new ArrayList<>();
        PriorityQueue<Integer> priorityQueue2=new PriorityQueue<>(list);  //如果list里面有元素，那么就会先将list里面的元素根据小根堆来创建优先级队列
        System.out.println("===========test3============");
    }
    public static void test3(Heap heap) {
        heap.creatHeap();
        System.out.println("堆排之前的结果:"+Arrays.toString(heap.elem));
        heap.heapSort();
        System.out.println("   堆排的结果:"+Arrays.toString(heap.elem));
    }
}
